package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.annotation.RequireLogin;
import cn.wolfcode.wolf2w.annotation.UserParam;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.redis.service.IHomepageVORedisService;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/homepage")
public class HomepageController {


    @Autowired
    private IHomepageVORedisService homepageVORedisService;

    @GetMapping("/viewnum")
    @RequireLogin
    public Object hotRegion(String id, @UserParam UserInfo userInfo) {

        // 判断判断窝的用户id是不是和当前登录用户id一致 一致表明是自己 不增加  不一致才增加
        if (!id.equals(userInfo.getId())) {

            int today = homepageVORedisService.todayViewnumIncrease(id);
            int total = homepageVORedisService.totalViewnumIncrease(id);

            // 封装成map
            Map<String, Integer> map = new HashMap<>();
            map.put("today", today);
            map.put("total", total);

            return JsonResult.success(map);
        } else {

            int today = homepageVORedisService.getTodayViewNum(id);
            int total = homepageVORedisService.getTotalViewNum(id);

            // 封装成map
            Map<String, Integer> map = new HashMap<>();
            map.put("today", today);
            map.put("total", total);

            return JsonResult.success(map);
        }
    }


}





































